package com.qianyu.project.web.controller.hyh;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.qianyu.project.core.annotation.FlowBegin;
import com.qianyu.project.core.annotation.FlowEntry;
import com.qianyu.project.entity.LeasePlan;
import com.qianyu.project.entity.ProjectInfo;
import com.qianyu.project.service.ILeasePlanService;
import com.qianyu.project.service.IProjectInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

/**
 * @author hyh
 * @date 2021/1/3118:05
 */
@RestController
@RequestMapping("leasePlan")
public class LeasePlanController {
    @Autowired
    ILeasePlanService iLeasePlanService;
    @Autowired
    IProjectInfoService iProjectInfoService;
    //查询项目信息

    @PostMapping("")
    public  void saveLeasePlan(@RequestBody  Map<String,Object> map){
        System.out.println(map);
        String str = "";

        LeasePlan lp=new LeasePlan();
        String time =LocalDate.now().toString();
         String year =time.substring(0,4);
        System.out.println(year);

        lp.setPlanName(map.get("planName").toString());
        lp.setPId((Integer) map.get("pId"));
        lp.setFillUser(map.get("fillUser").toString());
        lp.setUseTo(map.get("useTo").toString());

        lp.setFillDate((map.get("fillDate").toString()));
        System.out.println(lp);
       iLeasePlanService.save(lp);



    }

    @GetMapping("")
    public List<LeasePlan> getlist(@RequestParam Map<String,String> map){

        QueryWrapper qw=new QueryWrapper();
        String id=map.get("id");
        if(StringUtils.isNotBlank(id)){
            qw.eq("id",id);
        }
        String plan_name=map.get("plan_name");
        if(StringUtils.isNotBlank(plan_name)){
            qw.like("plan_name",plan_name);
        }
        String fill_user=map.get("fill_user");
        if(StringUtils.isNotBlank(fill_user)){
            qw.like("fill_user",fill_user);
        }
        String approve_status=map.get("approve_status");
        if(StringUtils.isNotBlank(approve_status)){
            qw.like("approve_status",approve_status);
        }
        String order=map.get("order");
        if(StringUtils.isNotBlank(order)){
            String[] orderargs=order.split("\\.");
            if(orderargs[1].equals("desc")){
                qw.orderByDesc(orderargs[0]);
            }else{
                qw.orderByAsc(orderargs[0]);
            }
        }

        List<LeasePlan> list = iLeasePlanService.list(qw);

        return list;
    }

    @GetMapping("/getProject")
    public  List<ProjectInfo> getProject(){
        return  iProjectInfoService.list();
    }
}
